package com.kevin.controller;

import com.kevin.service.KmeansService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.stereotype.Controller;

/**
 * <p></p>
 *
 * @author kevin
 * @create 2018-08-31 18:47
 **/
@Controller
public class PushMessageController {
    private static Logger LOGGER = LoggerFactory.getLogger(PushMessageController.class);

    @Autowired
    private KmeansService kmeansService;

    /**
     * 接收前端发送信息
     * 0:初始化地图、初始化数据仓库
     * 1:开始进行聚类运算（调用算法）
     * @param message
     */
    @MessageMapping("/kmeanswebsocket")
    public void pushMessage(String message){
        LOGGER.info("前端推送信息：{}",message);

        switch (message){
            case "0":
                kmeansService.initMap();
                break;
            case "1":
                kmeansService.executeCalculate();
                break;
            default:
                break;
        }
    }
}
